<?php
/** Yz_Descriptor_Abstract provides some basic methods of descriptor management
 *  The constructor implementation is up to the concrete classes
 *
 */
abstract class Yz_Descriptor_Abstract
    extends Yz_Hash
    implements Yz_Descriptor_Interface
{


    protected static $descriptors = array();

    public static function fetchByName($name)
    {
        $name = Yz_String::testNotEmpty($name);
        debug($name);
        $list = self::$descriptors;
        if (array_key_exists($name, $list)) {
            return $list[$name];
        }
        return null;
    }

    /**
     *  create a descriptor from values and store it by its item's class name
     *  @param string $name
     *  @param Yz_Hash
     *  @return Yz_Descriptor_Interface
     */
    public static function create($name, $values)
    {
        $name = Yz_String::testNotEmpty($name);
        debug($name);
        $d = new static($values);
        $list =& self::$descriptors;
        $list[$name] = $d;
        return $d;
    }

}
